package deployr.core;

import java.io.*;
import java.util.*;

public class ScanRemovedChecksum {

	public ScanRemovedChecksum(ScanListener listener, String currChecksum, String prevChecksum) {
		final List<String> prev = new LinkedList<String>();
		final List<String> curr = new LinkedList<String>();

		ScanListener prevListener = new ScanListener() {
			public void discovered(File root, File file) {}

			public void discovered(String path, String md5) {
				prev.add(path);
			}

			public void remove(String path) {}
		};

		ScanListener currListener = new ScanListener() {
			public void discovered(File root, File file) {}

			public void discovered(String path, String md5) {
				curr.add(path);
			}

			public void remove(String path) {}
		};

		new ScanChecksum(prevListener, prevChecksum);
		new ScanChecksum(currListener, currChecksum);

		for (String path : intersect(prev, curr))
			listener.remove(path);
	}

	private List<String> intersect(final List<String> curr, final List<String> prev) {
		List<String> removed = new LinkedList<String>();
		removed.addAll(curr);
		removed.removeAll(prev);
		return removed;
	}

}